//
//  ButtonView.m
//  LoanTeam15
//
//  Created by gynjobs on 2017/8/18.
//  Copyright © 2017年 cangming. All rights reserved.
//

#import "ButtonView.h"

@interface ButtonView  ()
@property(strong,nonatomic)UIButton *centerButton;
@end

@implementation ButtonView
-(instancetype)init{
    self = [super init];
    if (self) {
        [self addSubViewForSelf];
    }
    return self;
}
-(void)addSubViewForSelf{
    UIButton *centerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:centerButton];
    [centerButton addTarget:self action:@selector(clickCenterButton) forControlEvents:UIControlEventTouchUpInside];
    self.centerButton = centerButton;
    centerButton.layer.cornerRadius = VIEW_RADIUS;
    centerButton.layer.masksToBounds = YES;
}
-(void)setButtonTitleEnableColor:(NSString *)buttonTitleEnableColor{
    if (![_buttonTitleEnableColor isEqualToString:buttonTitleEnableColor]) {
        _buttonTitleEnableColor = buttonTitleEnableColor;
        [self.centerButton setTitleColor:[UIColor colorWithString:buttonTitleEnableColor] forState:UIControlStateNormal];
    }
}
-(void)setButtonTitleDisableColor:(NSString *)buttonTitleDisableColor{
    if (![_buttonTitleDisableColor isEqualToString:buttonTitleDisableColor]) {
        _buttonTitleDisableColor = buttonTitleDisableColor;
        [self.centerButton setTitleColor:[UIColor colorWithString:buttonTitleDisableColor] forState:UIControlStateDisabled];
    }
}
-(void)setButtonTitle:(NSString *)buttonTitle{
    if (![_buttonTitle isEqualToString:buttonTitle]) {
        _buttonTitle = buttonTitle;
        [self.centerButton setTitle:buttonTitle forState:UIControlStateNormal];
    }
}
//-(void)setButtonTitleColor:(NSString *)buttonTitleColor{
//    if (![_buttonTitleColor isEqualToString:buttonTitleColor]) {
//        _buttonTitleColor = buttonTitleColor;
//        [self.centerButton setTitleColor:[UIColor colorWithString:buttonTitleColor] forState:UIControlStateDisabled];
//    }
//}
//-(void)setButtonNomaleColor:(NSString *)ButtonNomaleColor{
//    if (![_ButtonNomaleColor isEqualToString:ButtonNomaleColor]) {
//        _ButtonNomaleColor = ButtonNomaleColor;
//        [self.centerButton layoutIfNeeded];
//         [self.centerButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithString:ButtonNomaleColor] size:self.centerButton.frame.size] forState:UIControlStateNormal];
//    }
//}
//-(void)setButtonSelectColor:(NSString *)buttonSelectColor{
//    if (![_buttonSelectColor isEqualToString:buttonSelectColor]) {
//        _buttonSelectColor = buttonSelectColor;
//        [self.centerButton layoutIfNeeded];
//         [self.centerButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithString:buttonSelectColor] size:self.centerButton.frame.size] forState:UIControlStateDisabled];
//    }
//}
//-(void)setButtonTitleEnableColor:(NSString *)buttonTitleEnableColor{
//    if (![_buttonTitleEnableColor isEqualToString:buttonTitleEnableColor]) {
//        _buttonTitleEnableColor = buttonTitleEnableColor;
//         [self.centerButton setTitleColor:[UIColor colorWithString:buttonTitleEnableColor] forState:UIControlStateNormal];
//    }
//}
-(void)layoutSubviews{
    [super layoutSubviews];
    [self.centerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(self.marginLeft==0?defaultMargin:self.marginLeft);
        make.center.equalTo(self);
        make.top.equalTo(self.mas_top).offset(self.marginTop==0?defaultMargin:self.marginTop);
    }];
    
    [self.centerButton layoutIfNeeded];
    
    if (![NSString isBlankStringWithString:self.ButtonEnableColor ]) {
        [self.centerButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithString:self.ButtonEnableColor] size:self.centerButton.frame.size] forState:UIControlStateNormal];
    }else{
        [self.centerButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithString:ButtonDefaultColor] size:self.centerButton.frame.size] forState:UIControlStateNormal];
    }
    if (![NSString isBlankStringWithString:self.buttonDisableColor]) {
        [self.centerButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithString:self.buttonDisableColor] size:self.centerButton.frame.size] forState:UIControlStateDisabled];
    }else{
         [self.centerButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithString:ButtonDefaultDisColor] size:self.centerButton.frame.size] forState:UIControlStateDisabled];
    }
}
-(void)clickCenterButton{
    if ([self.delegate  respondsToSelector:@selector(clickButtonWith:)]) {
        [self.delegate clickButtonWith:self];
    }
}
-(void)setIsEnable:(BOOL)isEnable{
    self.centerButton.enabled = isEnable;
}
@end
